/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.barrientosjunior.calculadora;


import akme.mobile.util.MathUtil;
/**
 *
 * @author Sidnei
 */
public class Estatistica {

    public static double valorZ(double x, double desl, double miu, double desvioPadrao){
        return (x + desl - miu)/desvioPadrao;
    }

    public static double combinacao(int n, int k){
        return fatorial(n)/(fatorial(k) * fatorial(n-k));
    }

    public static int fatorial(int x){
        if(x < 1){
            return 1;
        } else {
            int r = x;
            while (x > 1){
                x--;
                r = r * x;
            }
            return r;
        }
    }

    public static double distribuicaoBinomial(int n, int k, double p, double q){
        return combinacao(n,k) * MathUtil.pow(p, k) * MathUtil.pow( q, (n-k));
    }

    public static double distribuicaoDePoisson(int k, double lambda){
        return (MathUtil.pow(Math.E, lambda) * MathUtil.pow(lambda, k)) / fatorial(k);
    }
}
